<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="开始时间">
              <j-date placeholder="请选择开始日期" v-model="queryParam.taskBegin"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="结束时间">
              <j-date placeholder="请选择结束日期" v-model="queryParam.taskEnd"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('任务')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
<!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>-->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
        @change="handleTableChange">
				<template slot="timeoutmum" slot-scope="text, record, index">
				  <a @click="handleDeleteSelected(record, index)">{{text}}</a>
				</template>
      </a-table>
    </div>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import InsTaskModal from './modules/InsTaskModal'
  import { getAction } from '@/api/manage'
  import InsTaskItemList from './InsTaskItemList'
  import {initDictOptions,filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'

  export default {
    name: "InsTaskList",
    mixins:[JeecgListMixin],
    components: {
      InsTaskItemList,
      InsTaskModal
    },
    data () {
      return {
        description: '任务管理页面',
        // 表头
        columns: [
          {
            title:'部门名称',
            align:"center",
            dataIndex: 'departName'
          },
          {
            title:'下发任务数',
            align:"center",
            dataIndex: 'taskNum',
          },
          {
            title:'巡检数',
            align:"center",
            dataIndex: 'inspectedNum',
          },
          {
            title:'超时巡检数',
            align:"center",
            dataIndex: 'timeoutNum',
						scopedSlots: { customRender: 'timeoutmum' },
          },
        ],
        url: {
          list: "/inspect/report/depart",
          exportXlsUrl: "/inspect/report/exportDepartXls",
        },
        dictOptions:{
         taskStatus:[],
         ruleId:[],
         roleId:[],
         deptId:[],
        },
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['5', '10', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        selectedMainId:'',
        superFieldList:[],
        insTaskItemMainId: '',
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
        initDictOptions('sys_depart,depart_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'deptId', res.result)
          }
        })
      },
			handleDeleteSelected(record, index){
				 this.$router.push({ name: "inspect-insTaskList" ,query:{
					 month:record.month,
           departId: record.departId,
					 status:'4'
				 }})
			},
      // clickThenSelect(record) {
      //   return {
      //     on: {
      //       click: () => {
      //         this.onSelectChange(record.id.split(","), [record]);
      //       }
      //     }
      //   }
      // },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId=''
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
        this.insTaskItemMainId = selectionRows[0]['id']
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        this.onClearSelected()
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'roleName',text:'厂领导'})
        fieldList.push({type:'string',value:'taskNum',text:'任务数'})
        fieldList.push({type:'date',value:'inspectedNum',text:'巡检数'})
        fieldList.push({type:'date',value:'timeoutNum',text:'超时巡检数'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>
